package com.huawei.su;

/**
 * https://www.nowcoder.com/practice/fcf87540c4f347bcb4cf720b5b350c76?tpId=295&tqId=2227748&ru=%2Fpractice%2Fabc3fe2ce8e146608e868a70efebf62e&qru=%2Fta%2Fformat-top101%2Fquestion-ranking&sourceUrl=%2Fexam%2Foj
 */
public class BM19 {
    public static void main(String[] args) {
        int[] nums = {1, 2, 3, 2, 1, 4, 5, 6};
        findPeakElement(nums);
    }

    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * @param nums int整型一维数组
     * @return int整型
     */
    public static int findPeakElement(int[] nums) {
        // write code here
        int left = 0;
        int right = nums.length - 1;

        while (true) {
            if (left >= right) {
                break;
            }
            int middle = (left + right) / 2;
            if (nums[middle] > nums[middle + 1]) {
                right = middle;
            } else {
                left = middle + 1;
            }
        }
        return left;
    }
}
